package com.swusoft.schoolproject.controller;

import cn.dev33.satoken.util.SaResult;
import com.swusoft.schoolproject.utils.FilesUtils;
import lombok.RequiredArgsConstructor;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.apache.tomcat.util.http.fileupload.MultipartStream;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TextController {
    private final FilesUtils filesUtils;

    @PostMapping("/file")
    public SaResult testFile(@RequestParam("file")MultipartFile file){
        Map<String, Object> upload = filesUtils.upload(file);
        return SaResult.ok(upload.get("fileName").toString());
    }

}
